#include <stdio.h>
#include <stdlib.h>

struct Object
{
	int *p;
	long count;
};


int main(int argc, char **argv)
{
	int *p_i = (int*)malloc(sizeof(int));
	*p_i = 10;
	struct Object obj;
	obj.p = p_i;
	obj.count = 10;
	struct Object obj2;
	obj2.p = p_i;
	obj2.count = 12;
	printf("before swap:\n");
	printf("obj: %x \t %d\n", obj.p, obj.count);
	printf("obj2: %x \t %d\n", obj2.p, obj2.count);

	struct Object *p1_o = &obj;
	struct Object *p3_o = &obj2;
	
	int a = __sync_bool_compare_and_swap(&p1_o, p1_o, p3_o);
	printf("%d\n", a);
	printf("obj: %x \t %d\n", p1_o->p, p1_o->count);
	printf("obj2: %x \t %d\n", p1_o->p, p1_o->count);
	free(p_i);
	return 0;
}
